/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tcloudclient.connect;


import api.Beans.UserLogin;
import api.SessionBeans.TCloudServiceRemote;
import api.action.ActionPackageClient;
import api.action.ActionPackageServer;
import api.exception.TCloudAplicationException;
import api.localModel.LocalFileStatus;
import java.io.IOException;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Tomas
 */
public class ServerConnect {

    private TCloudServiceRemote createConnect() throws NamingException, IOException {
//        Properties props = new Properties();
//        props.load(new FileInputStream("jndi.properties"));
        InitialContext ctx = new InitialContext();
        TCloudServiceRemote testEJB = (TCloudServiceRemote) ctx.lookup("Service");
        return testEJB;
    }

    public void uploadChanges(ActionPackageServer actionPackage) throws NamingException, TCloudAplicationException, IOException {
        TCloudServiceRemote createConnect = createConnect();

        createConnect.uploadChanges(actionPackage);
    }

    public boolean isUpdate(Long userId, int accHeaderVersion) throws NamingException, IOException {
        TCloudServiceRemote createConnect = createConnect();
        
        return createConnect.isUpdate(userId, accHeaderVersion);
    }

    public ActionPackageClient downloadUpdateActions(LocalFileStatus localStatus) throws NamingException, IOException {
        TCloudServiceRemote createConnect = createConnect();

        return createConnect.downloadUpdateActions(localStatus);
    }
    
    public UserLogin login(String userName, String password) throws NamingException, IOException{
        TCloudServiceRemote createConnect = createConnect();
        
        return createConnect.loginUser(userName, password);
    }
    
    
}
